package winOrDie.graphicsInterface.RT;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;

import winOrDie.GameEngine.RT.mp.MapBoard;
import winOrDie.Net.Client.WoD_Client_RT;
import winOrDie.Net.Client.WoD_Peer;
import winOrDie.Net.Client.WoD_Peers_List;
import winOrDie.graphics.maps.Map_Board;

public class Composite_RT_Game extends Composite {

	WoD_Peer woDPeer = null;
	WoD_Client_RT woDClientRT = null;
	WoD_Peers_List woDPeersList = null;
	long TS_Start = 0L;
	long offset = 0;
	String mapName = null;
	
	private MapBoard mapBoard = null;
	
	public MapBoard getMapBoard() {
		return mapBoard;
	}

	public Composite_RT_Game(
			Composite parent, 
			int style,
			WoD_Peer woDPeer,
			WoD_Client_RT woDClientRT,
			WoD_Peers_List woDPeersList,
			long TS_Start,
			long offset,
			String mapName) 
	{
		super(parent, style);
		
		this.woDPeer = woDPeer;
		this.woDClientRT = woDClientRT;
		this.woDPeersList = woDPeersList;
		this.TS_Start = TS_Start;
		this.offset = offset;
		this.mapName = mapName;
		
		
		initialize();
	}

	private void initialize() {
		setSize(new Point(300, 200));
		setLayout(new FillLayout());
		
		
		
		
		
		get_Map_Board();
		pack();
		
		
		
		
		Runnable runnable = new Runnable() {
			
			@Override
			public void run() {
				mapBoard.render();
				if ((mapBoard==null) || (mapBoard.isDisposed())){return;}
				getDisplay().timerExec(MapBoard.FPS, this);
			}
		};
		
		
		
		getDisplay().timerExec(0, runnable);
//		getDisplay().asyncExec(runnable);
		
		
	}
	
	
	public MapBoard get_Map_Board()
	{
		if (mapBoard == null)
		{
			//mapBoard = new MapBoard(this, SWT.NONE);
			mapBoard = new MapBoard(this, SWT.NONE, woDPeer, woDClientRT, woDPeersList, TS_Start, offset, mapName);
			
			
		}
		
		return mapBoard;
	}

	
	
	
}
